<?php

namespace fankers\lib;

use fankers\helper\Http;

class Base
{
    public $http = null;
    public $redirect = '';

    public function __construct($params)
    {
        if (!isset($params['redirect']))throw new \Exception("回调地址不能为空");
        if (empty($this->redirect))$this->redirect = $params['redirect'];

        if ($this->http) {
            return $this->http;
        }
        $this->http = new Http();
    }

    public function randCharts($length)
    {
        $str = '';
        $charts = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
            'i', 'j', 'k', 'l','m', 'n', 'o', 'p', 'q', 'r', 's',
            't', 'u', 'v', 'w', 'x', 'y','z', 'A', 'B', 'C', 'D',
            'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L','M', 'N', 'O',
            'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y','Z',
            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
        ];

        $max = count($charts)-1;

        for($i=0;$i<$length;$i++) {

            $str .= $charts[rand(0, $max)];//rand($min,$max)生成介于min和max两个数之间的一个随机整数
        }
        return $str;
    }
}